import { BasicColumn, FormSchema } from "/@/components/Table"
import { render } from "/@/utils/common/renderUtils"
import { DescItem } from "/@/components/Description/index"
import { useI18n } from "/@/hooks/web/useI18n"
import { listAllPayIfDefine } from "../payIfDefine/payIfDefine.api"

const { t } = useI18n("")

export const columns: BasicColumn[] = [
  {
    title: t("对账批次号"),
    align: "left",
    dataIndex: "batchNo",
    width: 270,
  },
  {
    title: t("支付接口"),
    dataIndex: "ifCode",
    width: 130,
  },

  {
    title: t("账单类型"),
    dataIndex: "billTypeText",
    width: 120,
    customRender: ({ record }) => {
      const { billTypeText, billType } = record as any
      let color = "green"
      if (billType === "2") {
        color = "purple"
      }
      return render.renderTag(billTypeText, color)
    },
  },

  {
    title: t("订单号"),
    dataIndex: "orderNo",
    slot: "orderNo",
    width: 280,
  },
  {
    title: t("交易状态"),
    dataIndex: "channelTradeStatusText",
    width: 120,
    customRender: ({ record }) => {
      const { channelTradeStatusText, channelTradeStatus } = record as any
      const color = channelTradeStatus === "2" ? "green" : "purple"
      return render.renderTag(channelTradeStatusText, color)
    },
  },

  {
    title: t("交易金额"),
    dataIndex: "channelAmount",
    width: 130,
    customRender: ({ record }) => {
      return `￥${record.channelAmount}`
    },
  },
  {
    title: t("手续费"),
    dataIndex: "channelFeeAmount",
    width: 100,
    customRender: ({ record }) => {
      return record.channelFeeAmount || record.channelFeeAmount === 0 ? `￥${record.channelFeeAmount}` : "-"
    },
  },
  {
    title: t("交易成功时间"),
    dataIndex: "channelTradeTime",
    width: 160,
  },
]

export const searchFormSchema: FormSchema[] = [
  {
    label: t("商户号"),
    field: "mchNo",
    component: "Input",
  },
  {
    label: t("商户应用"),
    field: "appId",
    component: "Input",
  },
  {
    label: t("对账批次号"),
    field: "batchNo",
    component: "Input",
  },
  {
    label: t("支付接口"),
    field: "ifCode",
    component: "ApiSelect",
    componentProps: {
      api: listAllPayIfDefine,
      showSearch: true,
      allowClear: true,
      placeholder: "全部",
      resultField: "data",
      labelField: "ifName",
      valueField: "ifCode",
    },
  },
  {
    label: t("账单类型"),
    field: "billType",
    component: "JDictSelectTag",
    componentProps: {
      dictType: "pay_check_bill_type",
      placeholder: "全部",
      chooseOptionLabel: "全部",
      allowClear: true,
    },
  },
  {
    label: t("对账日期"),
    field: "billDate",
    component: "RangePicker",
    componentProps: {
      valueType: "Date",
    },
  },
]

export const inputFormSchemas: FormSchema[] = [
  {
    label: "",
    field: "id",
    component: "Input",
    show: false,
  },
  {
    label: t("平台商户号"),
    required: true,
    field: "mchNo",
    component: "Input",
    componentProps: {
      maxlength: 32,
    },
  },
  {
    label: t("平台应用id"),
    required: true,
    field: "appId",
    component: "Input",
    componentProps: {
      maxlength: 32,
    },
  },
  {
    label: t("批次号"),
    required: false,
    field: "batchNo",
    component: "Input",
    componentProps: {
      maxlength: 64,
    },
  },
  {
    label: t("渠道金额"),
    required: false,
    field: "channelAmount",
    component: "Input",
    componentProps: {
      maxlength: 10,
    },
  },
  {
    label: t("渠道手续费"),
    required: false,
    field: "channelFeeAmount",
    component: "Input",
    componentProps: {
      maxlength: 10,
    },
  },
  {
    label: t("渠道费率"),
    required: false,
    field: "channelRate",
    component: "Input",
    componentProps: {
      maxlength: 10,
    },
  },
  {
    label: t("渠道费率备注"),
    required: true,
    field: "channelRateNotes",
    component: "Input",
    componentProps: {
      maxlength: 300,
    },
  },
  {
    label: t("渠道商户号"),
    required: false,
    field: "channelMchNo",
    component: "Input",
    componentProps: {
      maxlength: 32,
    },
  },
  {
    label: t("渠道应用id"),
    required: true,
    field: "channelAppId",
    component: "Input",
    componentProps: {
      maxlength: 32,
    },
  },
  {
    label: t("渠道订单号"),
    required: false,
    field: "channelOrderNo",
    component: "Input",
    componentProps: {
      maxlength: 32,
    },
  },
  {
    label: t("渠道订单状态"),
    required: false,
    field: "channelTradeStatus",
    component: "Input",
    componentProps: {
      maxlength: 5,
    },
  },
  {
    label: t("渠道交易时间"),
    required: false,
    field: "channelTradeTime",
    component: "Input",
    componentProps: {
      maxlength: 0,
    },
  },
  {
    label: t("渠道用户标识"),
    required: false,
    field: "channelUser",
    component: "Input",
    componentProps: {
      maxlength: 32,
    },
  },
  {
    label: t("货币"),
    required: true,
    field: "currency",
    component: "Input",
    componentProps: {
      maxlength: 12,
    },
  },
  {
    label: t("平台订单号"),
    required: false,
    field: "orderNo",
    component: "Input",
    componentProps: {
      maxlength: 32,
    },
  },
  {
    label: t("支付接口"),
    required: true,
    field: "ifCode",
    component: "Input",
    componentProps: {
      maxlength: 32,
    },
  },
  {
    label: t("账单类型"),
    required: false,
    field: "billType",
    component: "Input",
    componentProps: {
      maxlength: 5,
    },
  },
  {
    label: t("账单日期"),
    required: false,
    field: "billDate",
    component: "Input",
    componentProps: {
      maxlength: 0,
    },
  },
  {
    label: t("更新时间"),
    required: true,
    field: "updatedAt",
    component: "Input",
    componentProps: {
      maxlength: 0,
    },
  },
  {
    label: t("更新者"),
    required: true,
    field: "updatedBy",
    component: "Input",
    componentProps: {
      maxlength: 32,
    },
  },
  {
    label: t("创建时间"),
    required: true,
    field: "createdAt",
    component: "Input",
    componentProps: {
      maxlength: 0,
    },
  },
  {
    label: t("租户id"),
    required: false,
    field: "tenantId",
    component: "Input",
    componentProps: {
      maxlength: 32,
    },
  },
  {
    label: t("主租户id"),
    required: false,
    field: "mainTenantId",
    component: "Input",
    componentProps: {
      maxlength: 32,
    },
  },
]

export const formDetailSchema: DescItem[] = [
  {
    label: t("平台商户号"),
    field: "mchNo",
  },
  {
    label: t("平台应用ID"),
    field: "appId",
  },
  {
    label: t("对账批次号"),
    field: "batchNo",
  },
  {
    label: t("账单类型"),
    field: "billTypeText",
  },
  {
    label: t("对账日期"),
    field: "billDate",
  },
  {
    label: t("支付接口"),
    field: "ifCode",
  },
  {
    label: t("交易金额"),
    field: "channelAmount",
  },
  {
    label: t("渠道手续费"),
    field: "channelFeeAmount",
  },
  {
    label: t("渠道费率"),
    field: "channelRate",
  },
  {
    label: t("渠道费率备注"),
    field: "channelRateNotes",
  },
  {
    label: t("渠道商户号"),
    field: "channelMchNo",
  },
  {
    label: t("渠道应用ID"),
    field: "channelAppId",
  },
  {
    label: t("平台订单号"),
    field: "orderNo",
  },
  {
    label: t("渠道订单号"),
    field: "channelOrderNo",
  },
  {
    label: t("渠道订单状态"),
    field: "channelTradeStatusText",
  },
  {
    label: t("渠道交易成功时间"),
    field: "channelTradeTime",
  },
  {
    label: t("渠道用户标识"),
    field: "channelUser",
  },
  {
    label: t("货币"),
    field: "currency",
  },

  {
    label: t("创建时间"),
    field: "createdAt",
  },
]
